package com.nova.android.tvlauncher.ui.fragment.atv

import android.os.Bundle
import com.nova.android.tvlauncher.AppCache
import com.nova.android.tvlauncher.R
import com.nova.android.tvlauncher.databinding.FragmentSelectAppAtvBinding
import com.nova.android.tvlauncher.ui.adapter.atv.HomeSelectAppAtvAdapter
import com.shudong.lib_base.ext.appContext
import com_github_lib_base.base.BaseVMFragment
import com_github_lib_base.base.BaseViewModel
import com_github_lib_base.bean.FavoriteApp
import com_github_lib_base.ext.getLaunchableApps
import com_github_lib_base.ext.rv.addModels
import com_github_lib_base.ext.rv.setup

class SelectAppATVFragment : BaseVMFragment<FragmentSelectAppAtvBinding, BaseViewModel>() {

    override fun initView() {

        //val apps = appContext.getLaunchableApps().toMutableList()
        mBind.rvApps.setup(mutableListOf()) {
            addType(FavoriteApp::class, R.layout.item_select_app_atv)
            onBind {
                HomeSelectAppAtvAdapter.bindData(this)


            }
        }

        val installedApps = appContext.getLaunchableApps().toMutableList()
        val favouriteApps = AppCache.favoriteAppList
        val selfPackageName = appContext.packageName // 替换为你的实际包名

        installedApps.removeIf { next ->
            favouriteApps.any { it.packageName == next.packageName || next.packageName == selfPackageName}
        }

        if (installedApps.isNotEmpty()) {
            mBind.rvApps.addModels(installedApps)
        } else {
            //showTipToast(R.string.app_text_32.stringValue())
        }

    }

    companion object {
        @JvmStatic
        fun newInstance() =
            SelectAppATVFragment().apply {
                arguments = Bundle().apply {

                }
            }
    }

}